<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>附近商家</title>
		<script src="__INDEX__/js/mui.min.js"></script>
		<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="__INDEX__/css/style.css" />
		<link rel="stylesheet" href="__INDEX__/css/iconfont.css" />
		<link rel="stylesheet" href="__INDEX__/css/mall.css" />
		<script src="__PUBLIC__/static/js/jquery.min.js"></script>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <h1 class="mui-title">附近商家</h1>
		</header>
		
		<div class="mui-content">
			<div class="shoplist_top">
				<div class="slist_address">
					<span class="mui-icon iconfont icon-refurbish"></span>
					<div><span class="mui-icon iconfont icon-dingwei" id="address">北湖区</span></div>
				</div>
			</div>
			<div class="shoplist_box">
				<ul class="index_sjlist" id="store_ul">
					
				</ul>
			</div>
		</div>
		<div id="allmap"></div>
		{include file="public/bottom" /}
	</body>

</html>
{include file="public/footer" /}
<script type="text/javascript">
	getAddress();
	//获取用户当前地址
function getAddress(){
	
	var script2 = document.createElement("script");
	script2.type = "text/javascript";
	script2.src = "http://developer.baidu.com/map/jsdemo/demo/convertor.js";
	document.body.appendChild(script2);
	
	
	var script1 = document.createElement("script");
	script1.type = "text/javascript";
	script1.src = "http://api.map.baidu.com/api?v=2.0&ak=grTHl4v1H6uGFLChfz0aB0uQG4XWQv0k&callback=my_getAddress";
	document.body.appendChild(script1);
	
}

function my_getAddress(){
	Axis = new Object();
	Axis.longitude = 113.022014;
	Axis.latitude = 25.779124;
	if (navigator.geolocation) {  //调用导航器geolocation函数
        navigator.geolocation.getCurrentPosition(function(position){
        	var latitude = position.coords.latitude;//y，纬度，
			var longitude = position.coords.longitude;//x，经度
			ggPoint = new BMap.Point(longitude,latitude);
			 //地图初始化
		    var bm = new BMap.Map("allmap");
		    bm.centerAndZoom(ggPoint, 15);
		    bm.addControl(new BMap.NavigationControl());
		    
		    //坐标转换完之后的回调函数
		    var convertor = new BMap.Convertor();
	        var pointArr = [];
	        pointArr.push(ggPoint);
	        convertor.translate(pointArr, 1, 5, function(points){
	        	var marker = new BMap.Marker(points);
			    bm.addOverlay(marker);
			    bm.setCenter(points);
			    var point = points['points'][0];
			    Axis.longitude = point.lng;
				Axis.latitude = point.lat;
					//获取详细地址信息
			    var gc = new BMap.Geocoder();  //初始化，Geocoder类
				gc.getLocation(point, function (rs) {
					  var addComp = rs.addressComponents;
				      var province 		= addComp.province;//获取省份
				      var city 			= addComp.city;//获取城市
				      var district 		= addComp.district;//区
				      var street 		= addComp.street;//街
				      var streetNumber 	= addComp.streetNumber //门牌号
				      $("#address").text(street+streetNumber);
	   			}); //进入总显示函数loand，函数名由自己定
			    
	        });
     	});
    } else {
         alert("您的浏览器不支持地理定位");//不支持
    }
   $.ajax({
   	type:"post",
   	data:{
   		longitude:Axis.longitude,
   		latitude:Axis.latitude
   	},
   	url:"{:url('index/index/get_agents')}",
   	success:function(data){
   		var html="";
   		if(data.list){
   			var list=data.list;
   			for(var o in list){
   				var agent=list[o];
   				var juli = agent.juli;
   				var diz = agent.address;
   				var begin_time = ''
   				var end_time = '';
   				if(!juli>0){
   					juli = "0";
   				}
   				if(diz && diz.length>0){
   					diz = agent.address;
   				}else{
   					diz = '暂无';
   				}
   				if(agent.start_time && agent.start_time.length>0){
   					begin_time = agent.start_time.substr(0,agent.start_time.length-3);
   				}else{
   					begin_time = '00:00';
   				}
   				if(agent.end_time && agent.end_time.length>0){
   					end_time = agent.end_time.substr(0,agent.end_time.length-3);;
   				}else{
   					end_time = '00:00';
   				}
				html+="<li>"
					  +"<a href='/index/index/shop_info?agent_id="+agent.id+"' class='clearfix'>"
					  +"<div class='index_sjimg'><img src='"+agent.logo+"'></div>"
					  +"<div class='index_sjinfo'>"
					  +"<div class='index_spname'>"+agent.agent_name+"</div>"
					  +"<div class='index_spstyle clearfix'>"
					  +"<span class=''>营业时间："+begin_time+'~'+end_time+"</span>"
					  +"<span class='index_sjdw' style='float:right;margin-right:15px'><i class='iconfont icon-fujin'></i>"+juli+"m</span>"
					  +"</div><div class='index_spadr'>"+diz+"</div>"
					  +"</div></a></li>";
			}
   			$("#store_ul").html(html);
   		}else{
   			$("#store_ul").html("<li>附近无商铺<li>");
   		}
   	}
   });
}

	mui.init();
	var aniShow = "pop-in";
	//页面跳转
	mui('#footer-list').on('tap', 'a', function() {
		var id = this.getAttribute('href');
		var href = this.href;
		mui.openWindow({
			id: id,
			url: this.href,
			show: {
				aniShow: aniShow
			},
			waiting: {
				autoShow: false
			}
		});
	});
</script>
